#include "TargetFarthestTankState.h"
#include "Taunts.h"
#include "World.h"
#include "470bot.h"
#include "Vector2.h"
#include "KalmanTank.h"
#include "TargetingHelper.h"

TargetFarthestTankState::TargetFarthestTankState(void)
{
}


TargetFarthestTankState::~TargetFarthestTankState(void)
{
}

Command TargetFarthestTankState::GetCommand(Agent* agent) {
	World* world = World::instance();
	tank_t* tank = agent->getTank();
	Vector2 tank_pos(tank->pos[0], tank->pos[1]);

	double max_dist = -99999999;
	KalmanTank* target = 0;

	for (unsigned int i = 0; i < world->enemies().size(); i++) {
		KalmanTank* ktank = &world->enemies().at(i);
		otank_t* otank = ktank->GetStruct();
		if (otank->status != "alive")
			continue;

		Vector2 ktank_pos(otank->pos[0], otank->pos[1]);

		double dist = (ktank_pos - tank_pos).magnitude();

		if (dist > max_dist) {
			max_dist = dist;
			target = ktank;
		}
	}

	if (target) {
		return TargetingHelper::Target(tank, target);
	}

	return Command(agent->getTank()->index, 0, 0, 0);
}